package com.cesgroup.zw.spring.boot.library.echarts.pie.many;

import com.cesgroup.zw.spring.boot.echarts.build.EChartsOption;
import com.cesgroup.zw.spring.boot.echarts.component.Title;
import com.cesgroup.zw.spring.boot.echarts.enums.FontWeight;
import com.cesgroup.zw.spring.boot.echarts.model.style.RichTextStyle;

/**
 * <p>多个饼图</p>
 * @author ytj
 * @date 2019/7/10 9:45
 */
@SuppressWarnings("serial")
public class ManyPieOption  extends EChartsOption{
    public ManyPieOption(ManyPieParam param){
        this.setBackgroundColor("#fff");
        this.setTitle(this.getTitle(param));

    }
    public Title[] getTitle(ManyPieParam param){
        Object[] names=param.getDataset().get("name");
        Object[][] colors=(Object[][]) param.getDataset().get("color");
        Title[] titles=new Title[names.length];
        for(int i=0;i<names.length;i++){
            Title title=new Title();
            title.setText(names[i]+"");
            title.setLeft(i*20+7+"%");
            title.setTop("65%");
            int num=i;
            title.setTextStyle(new RichTextStyle(){{
                this.setFontWeight(FontWeight.normal);
                this.setFontSize(16);
                this.setColor(colors[num][0]);
            }});
            titles[i]=title;
        }
        return titles;
    }
}
